package crew.blt.handsound.shared.domain;

import crew.blt.handsound.client.mvc.view.SitePage;

public enum AuthType {
	
	ROLE_ADMIN(
			SitePage.HOME,
			SitePage.USER,
			SitePage.EDIT_USER,
			SitePage.LOGOUT),
	ROLE_OPERATOR(
			SitePage.HOME,
			SitePage.LOGOUT),
	ROLE_NEWUSER(
			SitePage.HOME,
			SitePage.LOGOUT);

	final public SitePage [] accessiblePages;
	
	private AuthType(SitePage... accessiblePages) {
		this.accessiblePages = accessiblePages;
	}
	
	public static boolean authorizeUserPage(User user,SitePage page){
		if(user== null || page == null)
			return false;
		for(Auth a :user.getAuths()){
			final AuthType auth = AuthType.valueOf(a.getAuthority());
			for(SitePage p : auth.accessiblePages){
				if(p.equals(page))
					return true;
			}
		}
		return false;
	}
}
